package dyyx.util;

import java.lang.reflect.Field;
import java.util.HashMap;
import java.util.Map;

import io.netty.util.internal.PlatformDependent;
import io.netty.util.internal.logging.InternalLoggerFactory;

public class NettyUtil {
	
	// DIRECT_MEMORY_COUNTER
	private static final Field directMemoryCounterField = getField("DIRECT_MEMORY_COUNTER");



	
	public static void main(String[] args) throws Exception {
		
		
		
	}
	
	
	private static Field getField(String fieldName){
		try{
			Field fieldtmp = PlatformDependent.class.getDeclaredField(fieldName);
			fieldtmp.setAccessible(true);
			return fieldtmp;
		}catch(Throwable e){
			throw new RuntimeException("getField error,"+e);
		}
	}
	
	
	public synchronized static Map<String,Object> getInfo()throws Exception{
		Map map = new HashMap();
		
		
		
		map.put("defaultLogFactory", InternalLoggerFactory.getDefaultFactory().getClass().toString());

		map.put("hasUnsafe", PlatformDependent.hasUnsafe());
		map.put("maxDirectMemory", PlatformDependent.maxDirectMemory());
		map.put("useDirectBufferNoCleaner", PlatformDependent.useDirectBufferNoCleaner());

		map.put("addressSize", PlatformDependent.addressSize());
		map.put("directMemoryUsed", directMemoryCounterField.get(null));



		return map;
	}
	

	
}
